<template>
	<div class="app-container">
		<jk-card>
			<chart-view
				v-if="showView"
				:data-list-by-time-tow="dataListByTimeTow"
				:data-list-by-time="dataListByTime"
				:height="tableHeight + 20"
			></chart-view>
		</jk-card>
	</div>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import permissionMixin from '@/mixins/permission-mixin';
    import listView from './components/list-view';
    import chartView from './components/chart-view';
    import { formatDate, formatTime, pageConfig } from '/src/utils/jk/jk-tool';
    import { productionIotMachineCollectionDataListByTime } from '../../../api/equipmentMonitoring';

    export default {
        name: 'HeteroCeleReportForms',
        mixins: [permissionMixin, calHeight],
        components: {
            listView,
            chartView
        },
        data() {
            return {
                tableLoading: false,
                showView: false,
                dataListByTime: [],
                belongDate: '',
                dataListByTimeTow: []
            };
        },
        methods: {
            // 一号
            getDataListByTimeRequest() {
                const p1 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 00:00:00`,
                        endDataTime: `${this.belongDate} 02:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p2 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 02:00:01`,
                        endDataTime: `${this.belongDate} 04:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p3 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 04:00:01`,
                        endDataTime: `${this.belongDate} 06:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p4 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 06:00:01`,
                        endDataTime: `${this.belongDate} 08:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p5 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 08:00:01`,
                        endDataTime: `${this.belongDate} 10:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p6 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 10:00:01`,
                        endDataTime: `${this.belongDate} 12:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p7 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 12:00:01`,
                        endDataTime: `${this.belongDate} 14:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p8 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 14:00:01`,
                        endDataTime: `${this.belongDate} 16:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p9 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 16:00:01`,
                        endDataTime: `${this.belongDate} 18:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p10 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 18:00:01`,
                        endDataTime: `${this.belongDate} 20:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p11 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 20:00:01`,
                        endDataTime: `${this.belongDate} 22:00:00`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p12 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 22:00:01`,
                        endDataTime: `${this.belongDate} 23:59:59`,
                        signalIds: [2080],
                        uid: 787
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12]).then(value => {
                    this.dataListByTime = [...value[0], ...value[1], ...value[2], ...value[3], ...value[4], ...value[5], ...value[6], ...value[7], ...value[8], ...value[9], ...value[10], ...value[11]];
                    this.dataListByTime.sort((a, b) => new Date(a.belongTime) - new Date(b.belongTime));
                });
            },
            // // 二号
            getDataListByTimeRequestB() {
                const p1 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 00:00:00`,
                        endDataTime: `${this.belongDate} 02:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p2 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 02:00:01`,
                        endDataTime: `${this.belongDate} 04:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p3 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 04:00:01`,
                        endDataTime: `${this.belongDate} 06:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p4 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 06:00:01`,
                        endDataTime: `${this.belongDate} 08:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p5 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 08:00:01`,
                        endDataTime: `${this.belongDate} 10:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p6 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 10:00:01`,
                        endDataTime: `${this.belongDate} 12:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p7 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 12:00:01`,
                        endDataTime: `${this.belongDate} 14:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p8 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 14:00:01`,
                        endDataTime: `${this.belongDate} 16:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p9 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 16:00:01`,
                        endDataTime: `${this.belongDate} 18:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p10 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 18:00:01`,
                        endDataTime: `${this.belongDate} 20:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p11 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 20:00:01`,
                        endDataTime: `${this.belongDate} 22:00:00`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                const p12 = new Promise((resolve, reject) => {
                    const params = {
                        startDataTime: `${this.belongDate} 22:00:01`,
                        endDataTime: `${this.belongDate} 23:59:59`,
                        signalIds: [2080],
                        uid: 788
                    };
                    productionIotMachineCollectionDataListByTime(params).then(res => {
                        if (res.data.status === 200) {
                            resolve(res.data.res.tableData || []);
                        }
                    });
                });
                Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12]).then(value => {
                    this.dataListByTimeTow = [...value[0], ...value[1], ...value[2], ...value[3], ...value[4], ...value[5], ...value[6], ...value[7], ...value[8], ...value[9], ...value[10], ...value[11]];
                    this.dataListByTimeTow.sort((a, b) => new Date(a.belongTime) - new Date(b.belongTime));
                    this.showView = true;
                });
            },
            async getDependentData() {
                await this.getDataListByTimeRequest();
                await this.getDataListByTimeRequestB();
            }
        },
        mounted() {
            this.belongDate = formatDate(Date.now());
            this.getDependentData();
        }
    };
</script>
<style scoped>
</style>
